package jwdt.xadmin.custom.bean;

import java.sql.SQLException;

import jwdt.common.util.CacheUtil;

import com.ezerg.db.Jdb;
import com.ezerg.db.annotation.Column;
import com.ezerg.db.annotation.Table;

@Table(name="t_custom", keys={"id"}, comment="")
public class TCustom implements java.io.Serializable {

	private static final long serialVersionUID = 1L;

	@Column(value="id", comment="")
	private Integer id;
	
	@Column(value="name", comment="客户名")
	private String name;
	
	@Column(value="type", comment="")
	private Integer type;
	
	@Column(value="code", comment="")
	private String code;
	
	@Column(value="email", comment="")
	private String email;
	
	@Column(value="owner", comment="")
	private Integer owner;
	
	@Column(value="content", comment="")
	private String content;
	
	@Column(value="adder", comment="")
	private String adder;
	
	@Column(value="tel", comment="")
	private String tel;
	
	@Column(value="fax", comment="")
	private String fax;
	
	@Column(value="zipcode", comment="")
	private String zipcode;
	
	@Column(value="dt", comment="")
	private String dt;
	
	@Column(value="logdt", comment="")
	private String logdt;
	
	public String getLogdt() {
		return logdt;
	}

	public void setLogdt(String logdt) {
		this.logdt = logdt;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Integer getOwner() {
		return owner;
	}

	public void setOwner(Integer owner) {
		this.owner = owner;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getAdder() {
		return adder;
	}

	public void setAdder(String adder) {
		this.adder = adder;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	public String getDt() {
		return dt;
	}

	public void setDt(String dt) {
		this.dt = dt;
	}
	
	public String getTypeName(){
		return Jdb.get().queryForString("SELECT mxmc FROM jwdt_zd_flmx WHERE flid=? order by px", new Object[]{this.type});
	}
	
	public static int getIdByDt(String dt) {
		return Jdb.get().queryForInt("select id from t_custom where dt=?", new Object[]{dt}, CacheUtil.C0);
	}
	
	public static void insertCascade(Integer id, Integer contactsId) throws SQLException {
		Jdb.get().execute("insert into t_custom_contacts (custom_id, contacts_id) values (?,?)", new Object[]{id, contactsId});
	}
	
	public static void deleteCascade(Integer id) throws SQLException {
		Jdb.get().execute("DELETE FROM t_contacts WHERE EXISTS (SELECT DISTINCT contacts_id FROM t_custom_contacts WHERE custom_id = ?)", new Object[]{id});
		Jdb.get().execute("delete from  t_custom_contacts where custom_id = ?", new Object[]{id});
	}
}
